package name.sakanacatcher.repository;

import name.sakanacatcher.entity.User;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface UserRepository extends JpaRepository<User, Integer> {

    User getById(int id);

    void deleteById(int id);

    List<User> getUsersByComId(int cid);


    User getByUsername(String name);

    boolean existsByUsername(String name);

    boolean existsById(int id);

//    @Query(value = "select u.id id, u.name name, group_concat(r.oid + r.position) roles,group_concat(o.name) orgs, gender, org, status, uclass, avatar from user u, user_roles ur, role r, org o where ur.uid = u.id and ur.rid = r.id and r.oid = o.id group by u.id", nativeQuery = true)
//    List<Map<String, Object>> getTable();

    @Query(value = "select * from user", nativeQuery = true)
    List<Map<String, Object>> getUsers();

    @Query(value = "select * from user where name = :name",nativeQuery = true)
    public Map<String, Object> getMajorByUsername(@Param("name") String name);

    @Query(value = "select * from user where id = :id",nativeQuery = true)
    Map<String, Object> getDetailById(@Param("id") int id);
}
